/*
 *  $Id: PlayerAbilityCard.cs 1053 2010-05-19 10:05:23Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima {
    /// <summary>
    /// Способность игрока.
    /// В отличие от простых способностей, карта может быть взята в колоду, но при начале игры автоматически переносится в способности игрока и не может попасть в руки.
    /// </summary>
    public abstract class PlayerAbilityCard: AbilityCard {
        public PlayerAbilityCard(string id): base(id) {}

        public override CardType CardType {
            get { return CardType.PlayerAbility; }
        }

        public override int DefaultMaxCount {
            get { return 1; }
        }

        public override bool DefaultAllowInDefence {
            get { return false; }
        }
    }

    /// <summary>
    /// Генерализованная карта способности, приводящая TargetArgs к определенному типу
    /// </summary>
    public abstract class PlayerAbilityCard<T>: PlayerAbilityCard {
        private bool _isObjectTarget;

        public PlayerAbilityCard(string id): base(id) {
            _isObjectTarget = typeof(T).IsSubclassOf(typeof(AbstractObject));
            if (_isObjectTarget) LogMessage = Resources.Game.CastTargetAbility;
        }

        public sealed override void ManaCostAction(TargetArgs args, ElementValues manas) {
            if (args is TargetArgs<T>)
                ManaCostAction((TargetArgs<T>) args, manas);
            else
                base.ManaCostAction(args, manas);
        }
        public sealed override bool IsPossibleAction(TargetArgs args) {
            if (args is TargetArgs<T>)
                return IsPossibleAction((TargetArgs<T>) args);
            else
                return base.IsPossibleAction(args);
        }
        public sealed override void LogAction(Log log, TargetArgs args) {
            if (args is TargetArgs<T>)
                LogAction(log, (TargetArgs<T>) args);
            else
                base.LogAction(log, args);
        }
        public sealed override void DoAction(TargetArgs args) {
            if (args is TargetArgs<T>)
                DoAction((TargetArgs<T>) args);
            else
                base.DoAction(args);
        }

        protected virtual void ManaCostAction(TargetArgs<T> args, ElementValues manas) {
            base.ManaCostAction(args, manas);
        }
        protected virtual bool IsPossibleAction(TargetArgs<T> args) {
            return base.IsPossibleAction(args);
        }
        protected virtual void LogAction(Log log, TargetArgs<T> args) {
            if (_isObjectTarget && LogMessage != null)
                log.Add(LogMessage, args.Caster, this, args.Target);
            else
                base.LogAction(log, args);
        }
        protected virtual void DoAction(TargetArgs<T> args) {
            base.DoAction(args);
        }
    }
}
